% A sample script, which shows the usage of functions, included in
% A sample script, which shows the usage of functions, included in
% PCA-based face recognition system (Eigenface method)
%
% See also: CREATEDATABASE, EIGENFACECORE, RECOGNITION

% Original version by Amir Hossein Omidvarnia, October 2007
%                     Email: aomidvar@ece.ut.ac.ir                  

clear all
clc
close all

% You can customize and fix initial directory paths
TrainDatabasePath = ('C:\Users\Anderson\workspace\TCC-Server\WebContent\PCA_Face_Recognition_System\TrainDatabase' );
TestDatabasePath = ('C:\Users\Anderson\workspace\TCC-Server\WebContent\Imagens\testFile.jpg');


% prompt = {'Enter test image name (a number between 1 to 10):'};
% dlg_title = 'Input of PCA-Based Face Recognition System';
% num_lines= 1;
% def = {'1'};

% TestImage  = inputdlg(prompt,dlg_title,num_lines,def);
% TestImage = strcat(TestDatabasePath,'\',char(TestImage),'.jpg');
TestImage = TestDatabasePath;
im = imread(TestImage);

T = CreateDatabase(TrainDatabasePath);
[m, A, Eigenfaces] = EigenfaceCore(T);
OutputName = Recognition(TestImage, m, A, Eigenfaces);
if strcmp(OutputName, 'notfound.jpg')
fid = fopen('C:\Users\Anderson\workspace\TCC-Server\WebContent\PCA_Face_Recognition_System\resposta.txt','w');
fprintf(fid,'%s',OutputName);
status = fclose(fid);
else
SelectedImage = strcat(TrainDatabasePath,'\',OutputName);
SelectedImage = imread(SelectedImage);

imshow(im)
title('Test Image');
figure,imshow(SelectedImage);
title('Equivalent Image');

%str = strcat('Matched image is :  ',OutputName);
%disp(str)
fid = fopen('C:\Users\Anderson\workspace\TCC-Server\WebContent\PCA_Face_Recognition_System\resposta.txt','w');
fprintf(fid,'%s',OutputName);
status = fclose(fid);
end

